/**
 * Created by Liberty on 2015/8/28.
 */
$(function(){
    $("#file-a").change(function(){
        var filename=$("#file-a").val().split("\\").pop();
        // alert(filename);
        // var filename=$(":file").attr("value");
        // alert(filename);
        // var filename=$("#file-a").attr("value");

        var span="<div><span class='glyphicon glyphicon-file'></span>x</div>";
        var str=span.replace('x',filename);
        if(typeof(filename)!="undefined"){
            $("#input0a div").remove();
            $("#input0a").prepend(str);
        }
        // var file=$("#file-a").val();
        // var fileName=getFileName(file);
        // $("#input0a").prepend("<span class='glyphicon glyphicon-file'></span>");
    });
});
$(document).ready(function() {
    $("#btn1").click(function () {
        var x = new Number($("#table1 tbody tr").length).toString();
        var name1 = "course[chapter][x][chname]";
        var str1 = name1.replace('x', x);
        var name2 = "course[chapter][x][describtion]";
        var str2 = name2.replace('x', x);
        $("#table1").append("<tr> <td><input type='text' value=''></td><td><textarea rows='2' wrap='hard'></textarea></td></tr>");
        var att1 = document.createAttribute("name");
        att1.value = str1;
        var att2 = document.createAttribute("name");
        att2.value = str2;
        var tr1 = $("#table1 tbody tr").last().find("input");
        tr1.attr("name", str1);
        var tr2 = $("#table1 tbody tr").last().find("textarea");
        tr2.attr("name", str2);
    });
    $("#btn2").click(function () {
        $("#table1 tbody tr").last().remove();
    });
});
$(function(){
    $("#select1").unbind("change",eDropLangChange).bind("change",eDropLangChange);
    $("#select2").unbind("change",eDropFrameChange).bind("change",eDropFrameChange);
});

var eDropLangChange=function(){
    var selectedValue=$(this).val();
    $("#select2").children("span").each(function(){
        $(this).children().clone().replaceAll($(this));
    });
    if(parseInt(selectedValue)!=0){
        $("#select2").children("option[parentid!='"+selectedValue+"'][value!='0']").each(function(){
            $(this).wrap("<span style='display: none'></span>");
        });
    }
};
var eDropFrameChange=function(){
    $("#select1").val($(this).children("option:selected").attr("parentid"));
};
